import accountServices, { EVENT_LOGIN } from '../../../services/account'
import userStore from '../../../store/user'
import { USER_INFO } from '../../../constants/user'
let util = require('../../../utils/index');
let app = getApp()

Page({
  /**
   * 获取用户信息处理函数
   * @param {object} event
   */
      data:{
    initLoading:true
  },
  gotoLoginPage(){
    util.default.go('../login/Login')
  },

  // 注册
  gotoRegisterPage({ detail: { errMsg } }){
    if (errMsg === 'getUserInfo:ok') {
      //RegisterLoginByWeixinAsync
      accountServices.loginByWeixinAsync(() => {
        //accountServices.eventEmitter.emit(EVENT_LOGIN, userStore.getData(USER_INFO))
        util.default.go('../register/step1/RegisterStep1')
      });
    }
  },
  gotoRegister(){
    util.default.go('../register/step1/RegisterStep1')
  },
  onLoad: function (options) {
    //小程序启动就是登录页,页面先隐藏,获取完用户信息再显示或者跳转.
    var _this = this;
    accountServices.ensureLogined((userInfo) => {
      setTimeout(function(){
        wx.hideToast();
        _this.setData({
          initLoading:false
        });
      },200);
    });
  },
})